/*----------------------------------------------------*
       Project : Covid 19
       Purpose : Appendix Regressions for ASHA sample
       updated : September 29, 2021
*-----------------------------------------------------*/

*=======================================================================*

** SETTING UP
version 15
clear all
pause on
set more off
qui cap log c
set scheme plotplain



loc path_LM = "/Users/louis-maeljean/Dropbox (MIT)/West Bengal Information Campaign/AER_I/for_submission"
loc path = "`path_LM'" 		//other users should change this

cd "`path'"


** LOADING PROCESSED DATASET **
use "`path'/data/outcomes_asha_reg_input3", clear   // look at 01_processing and 02_newprocessing for how this was generated
cd "`path'/output"

*========================================================================*

/*PLEASE READ:

In this file all appendix tables for the ASHA Survey are implemented. 
This concerns Tables A2-A5, A12, A16-A20.
	
Throughout the file we use the following variables that aren't self-explanatory:
	flw_households		: number of households under the ASHA's supervison
	phase 		  		: survey phase (ranging from 0 to 5 where 1 is the window for the main analysis -07-10 may-)
	interview_round		: current ASHA's interview round (e.g. 3 if ASHA is being interviewed for the third time)
	total rounds		: total number of rounds the ASHA has been interviwed
	district			: district the ASHA lives in
	exit_flag			: 1 on the date where the ASHA leaved the study (missing if ASHA never attrited)
	fever				: number of fever cases reported to the ASHA in the last 3 days
	respiratory_count 	: number of respiratory cases reported to the ASHA in the last 3 days
	total_symptoms_fr 	: sum of fever and respiratory
	any_symptoms_fr		: binary for whether either fever or respiratory is positive
	flw_fever			: binary for whether ASHA experienced fever her/himself
	flw_respiratory_count:binary for whether ASHA experienced respiratory issues her/himself
	
*/
*========================================================================*



************************************************************************************
************************************************************************************
**********************I.Supplementary Tables****************************************
************************************************************************************
************************************************************************************




*=========================================================================================================
                    *Supplementary Table A2 | Reports Received by ASHAs Within 2 Days of Message*
*=========================================================================================================
preserve

keep if phase == 1 & id_date < td(9may2020)         // This restricts the data from 7th to 8th may.

//Fever
reg fever Treatment Wflw_households i.id_date i.district i.interview_round i.smartphone, vce(cluster pincode)
su fever if e(sample) & Treatment == 0
loc depvarmean = r(mean)
outreg2 using "Tables/TableA2", ///
keep(Treatment) replace ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Fever Cases)

//Respiratory
reg respiratory_count Treatment Wflw_households i.id_date i.district i.interview_round i.smartphone, vce(cluster pincode)
su respiratory_count if e(sample) & Treatment == 0
loc depvarmean = r(mean) 
outreg2 using "Tables/TableA2", ///
keep(Treatment) append ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Respiratory Cases)

//Any Symptom
reg any_symptoms_fr Wflw_households Treatment i.id_date i.district i.smartphone i.interview_round, vce(cluster pincode)
su any_symptoms_fr if e(sample) & Treatment == 0
loc depvarmean = r(mean)
outreg2 using "Tables/TableA2", ///
keep(Treatment) append ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Any Symptom Reported)

//Total Symptoms
reg total_symptoms_fr  Wflw_households Treatment  i.id_date i.district i.interview_round i.smartphone, vce(cluster pincode)
su total_symptoms_fr if e(sample) & Treatment == 0
loc depvarmean = r(mean)
outreg2 using "Tables/TableA2", ///
keep(Treatment) append ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Total Number of Cases)


restore




*==========================================================================================================
             *Supplementary Table A3 | Reports Received by ASHAs Within 3 Days of Message*
*==========================================================================================================
preserve

keep if phase == 1 & id_date < td(10may2020)         // This restricts the data from 7th to 9th may.

//Fever
reg fever Treatment Wflw_households i.id_date i.district i.interview_round i.smartphone, vce(cluster pincode)
su fever if e(sample) & Treatment == 0
loc depvarmean = r(mean)
outreg2 using "Tables/TableA3", ///
keep(Treatment) replace ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Fever Cases)

//Respiratory
reg respiratory_count Treatment Wflw_households i.id_date i.district i.interview_round i.smartphone, vce(cluster pincode)
su respiratory_count if e(sample) & Treatment == 0
loc depvarmean = r(mean) 
outreg2 using "Tables/TableA3", ///
keep(Treatment) append ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Respiratory Cases)

//Any Symptom
reg any_symptoms_fr Wflw_households Treatment i.id_date i.district i.smartphone i.interview_round, vce(cluster pincode)
su any_symptoms_fr if e(sample) & Treatment == 0
loc depvarmean = r(mean)
outreg2 using "Tables/TableA3", ///
keep(Treatment) append ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Any Symptom Reported)

//Total Symptoms
reg total_symptoms_fr  Wflw_households Treatment  i.id_date i.district i.interview_round i.smartphone, vce(cluster pincode)
su total_symptoms_fr if e(sample) & Treatment == 0
loc depvarmean = r(mean)
outreg2 using "Tables/TableA3", ///
keep(Treatment) append ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Control Mean", `depvarmean') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Total Number of Cases)

restore





*=================================================================================================
                    *Supplementary Table A4 | Reports Received by ASHAs over time*
*=================================================================================================
/* 
This section lays down code that will be used for Supplementary Figure S9, S10 and S11
The code is structured in the following manner for each regression:
		1) Run phase regression
		2) Get control means for each phase
		3) Export regression table
		4) Store q-values (used in Figures S9 and S11)
*/


//Fever
reghdfe fever c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)
estimates store Fever

quietly sum fever if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)


preserve

	parmest, norestore
	keep in 12/16 //Only keep the coefficiens of interest (Treatment # phase)
	qqvalue p, method(hochberg) qvalue(q)
	loc fq1 = round(q[1], 0.001) //Fever q-value for treatment X phase 1 
	loc fq1 : di %9.3f `fq1'
	loc fq2 = round(q[2], 0.001)
	loc fq2 : di %9.3f `fq2'
	loc fq3 = round(q[3], 0.001)
	loc fq3 : di %9.3f `fq3'
	loc fq4 = round(q[4], 0.001)
	loc fq4 : di %9.3f `fq4'
	loc fq5 = round(q[5], 0.001)
	loc fq5 : di %9.3f `fq5'
	
restore

outreg2 using "Tables/TableA4", ///
replace keep(Treat*) ///
label tex(frag) stats(coef se pval tstat) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
stnum(replace tstat= `fq1' if pval == pval[1], replace tstat= `fq2' if pval == pval[2], replace tstat= `fq3' if pval == pval[3], replace tstat= `fq4' if pval == pval[4], replace tstat= `fq5' if pval == pval[5]) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Fever Cases)


//Respiratory
reghdfe respiratory_count c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)
estimates store Respiratory

quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)

preserve

	parmest, norestore
	keep in 12/16 //Only keep the coefficiens of interest (Treatment # phase)
	qqvalue p, method(hochberg) qvalue(q)
	loc rq1 = round(q[1], 0.001)						//Respiratory q-value for treatment X phase 1
	loc rq1 : di %9.3f `rq1'
	loc rq2 = round(q[2], 0.001)
	loc rq2 : di %9.3f `rq2'
	loc rq3 = round(q[3], 0.001)
	loc rq3 : di %9.3f `rq3'
	loc rq4 = round(q[4], 0.001)
	loc rq4 : di %9.3f `rq4'
	loc rq5 = round(q[5], 0.001)
	loc rq5 : di %9.3f `rq5'
	
restore

outreg2 using "Tables/TableA4", ///
 append keep(Treat*) ///
label tex(frag) stats(coef se pval tstat ) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) /// 
stnum(replace tstat= `rq1' if pval == pval[1], replace tstat= `rq2' if pval == pval[2], replace tstat= `rq3' if pval == pval[3], replace tstat= `rq4' if pval == pval[4], replace tstat= `rq5' if pval == pval[5]) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Respiratory Cases)



//Get the p-values for the one-sided test that Resp - Fever < 0 against the null that Resp - Fever >= 0
postfile q_values p_diff using Q_values, replace //create file named Q_values where p_values will be stored (p_diff) to perform multiple hypothesis testing

quietly reg fever c.Wflw_households##phase Treatment#phase i.id_date i.phase#district i.phase#smartphone_yn i.phase#interview_round if phase > 0
	estimates store fever
quietly reg respiratory_count c.Wflw_households##phase Treatment#phase i.id_date i.phase#district i.phase#smartphone_yn i.phase#interview_round if phase > 0
	estimates store respiratory

quietly suest fever respiratory, cluster(pincode)

test _b[respiratory_mean:1.Treatment#1.phase] - _b[fever_mean:1.Treatment#1.phase] = 0
	loc p1 = round(normal(-1*sqrt(r(chi2))),0.001)
	post q_values (`p1')
	loc p1 : di %9.3f `p1'
quietly test _b[respiratory_mean:1.Treatment#2.phase] - _b[fever_mean:1.Treatment#2.phase] = 0
	loc p2 = round(normal(-1*sqrt(r(chi2))),0.001)
	post q_values (`p2')
	loc p2 : di %9.3f `p2'
quietly test _b[respiratory_mean:1.Treatment#3.phase] - _b[fever_mean:1.Treatment#3.phase] = 0
	loc p3 = round(normal(-1*sqrt(r(chi2))),0.001)
	post q_values (`p3')
	loc p3 : di %9.3f `p3'
 test _b[respiratory_mean:1.Treatment#4.phase] - _b[fever_mean:1.Treatment#4.phase] = 0
	loc p4 = round(normal(-1*sqrt(r(chi2))),0.001)
	post q_values (`p4')
	loc p4 : di %9.3f `p4'
quietly test _b[respiratory_mean:1.Treatment#5.phase] - _b[fever_mean:1.Treatment#5.phase] = 0
	loc p5 = round(normal(sqrt(r(chi2))),0.001)
	post q_values (`p5')
	loc p5 : di %9.3f `p5'
	
postclose q_values

preserve

	use Q_values, clear
	qqvalue p_diff, method(hochberg) qvalue(q_diff)
	loc q_diff1 = round(q_diff[1], 0.001)						
	loc q_diff1 : di %9.3f `q_diff1'
	loc q_diff2 = round(q_diff[2], 0.001)
	loc q_diff2 : di %9.3f `q_diff2'
	loc q_diff3 = round(q_diff[3], 0.001)
	loc q_diff3 : di %9.3f `q_diff3'
	loc q_diff4 = round(q_diff[4], 0.001)
	loc q_diff4 : di %9.3f `q_diff4'
	loc q_diff5 = round(q_diff[5], 0.001)
	loc q_diff5 : di %9.3f `q_diff5'
	
restore
	 
//Any symptoms
reghdfe any_symptoms_fr c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)
estimates store ASymptoms

quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)


preserve

	parmest, norestore
	keep in 12/16 //Only keep the coefficiens of interest (Treatment # phase)
	qqvalue p, method(hochberg) qvalue(q)
	loc aq1 = round(q[1], 0.0001)				//Any Symptoms q-value for treatment X phase 1
	loc aq1 : di %9.3f `aq1'
	loc aq2 = round(q[2], 0.001)
	loc aq2 : di %9.3f `aq2'
	loc aq3 = round(q[3], 0.001)
	loc aq3 : di %9.3f `aq3'
	loc aq4 = round(q[4], 0.001)
	loc aq4 : di %9.3f `aq4'
	loc aq5 = round(q[5], 0.001)
	loc aq5 : di %9.3f `aq5'
	
restore

outreg2 using "Tables/TableA4", ///
 append keep(Treat*) ///
label tex(frag) stats(coef se pval tstat) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
stnum(replace tstat= `aq1' if pval == pval[1], replace tstat= `aq2' if pval == pval[2], replace tstat= `aq3' if pval == pval[3], replace tstat= `aq4' if pval == pval[4], replace tstat= `aq5' if pval == pval[5]) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Any Symptom Reported)


//Total symptoms 
reghdfe total_symptoms_fr c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)
estimates store TSymptoms

quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)



preserve

	parmest, norestore
	keep in 12/16 //Only keep the coefficiens of interest (Treatment # phase)
	qqvalue p, method(hochberg) qvalue(q)
	loc tq1 = round(q[1], 0.001)							//Total Symptoms q-value for treatment X phase 1
	loc tq1 : di %9.3f `tq1'
	loc tq2 = round(q[2], 0.001)
	loc tq2 : di %9.3f `tq2'
	loc tq3 = round(q[3], 0.001)
	loc tq3 : di %9.3f `tq3'
	loc tq4 = round(q[4], 0.001)
	loc tq4 : di %9.3f `tq4'
	loc tq5 = round(q[5], 0.001)
	loc tq5 : di %9.3f `tq5'
	
restore

outreg2 using "Tables/TableA4", ///
 append keep(Treat*) ///
label tex(frag) stats(coef se pval tstat) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
stnum(replace tstat= `tq1' if pval == pval[1], replace tstat= `tq2' if pval == pval[2], replace tstat= `tq3' if pval == pval[3], replace tstat= `tq4' if pval == pval[4], replace tstat= `tq5' if pval == pval[5]) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Total Symptoms Reported)


erase "Q_values.dta" 



*=============================================================================================================
                 *Supplementary Table A5 | Reports Received over time by ASHA Who Never Attrit*
*=============================================================================================================
preserve

keep if missing(exit_phase) //only keep sample of ASHAs who never attrited from the study

//Fever
reghdfe fever c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)

quietly sum fever if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum fever if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)

outreg2 using "Tables/TableA5", ///
replace keep(Treat*) ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Fever Cases)
	
//Respiratory
reghdfe respiratory_count c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)

quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum respiratory_count if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)

outreg2 using "Tables/TableA5", ///
 append keep(Treat*) ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Number of Respiratory Cases)
	 
//Any symptoms
reghdfe any_symptoms_fr c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)

quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum any_symptoms_fr  if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)

outreg2 using "Tables/TableA5", ///
 append keep(Treat*) ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Any Symptom Reported)


//Total symptoms 
reghdfe total_symptoms_fr c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)

quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum total_symptoms_fr if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)

outreg2 using "Tables/TableA5", ///
 append keep(Treat*) ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Total Symptoms Reported)


restore 





*==============================================================================================
        *Supplementary Figure A12 | Fever and Respiratory Symptoms experienced by ASHAs*
*==============================================================================================
preserve

//ASHA own Fever
reghdfe flw_fever c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)
estimates store ASHAFever

quietly sum flw_fever if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum flw_fever if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum flw_fever if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum flw_fever if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum flw_fever if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)

outreg2 using "Tables/TableA12", ///
replace keep(Treat*) ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Fever Cases)



//ASHA own Respiratory
reghdfe flw_respiratory_count c.Wflw_households##phase TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 if phase > 0, absorb(id_date phase#district phase#smartphone_yn phase#interview_round) cluster(pincode)
estimates store ASHARespiratory

quietly sum flw_respiratory_count if  e(sample) & Treatment == 0 & phase == 1
loc depvarmean1 = r(mean)
quietly sum flw_respiratory_count if  e(sample) & Treatment == 0 & phase == 2
loc depvarmean2 = r(mean)
quietly sum flw_respiratory_count if  e(sample) & Treatment == 0 & phase == 3
loc depvarmean3 = r(mean)
quietly sum flw_respiratory_count if  e(sample) & Treatment == 0 & phase == 4
loc depvarmean4 = r(mean)
quietly sum flw_respiratory_count if  e(sample) & Treatment == 0 & phase == 5
loc depvarmean5 = r(mean)

outreg2 using "Tables/TableA12", ///
append keep(Treat*) ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) adec(3) ///
addstat("Contr. Mean Phase 1", `depvarmean1',"Contr. Mean Phase 2", `depvarmean2',"Contr. Mean Phase 3", `depvarmean3',"Contr. Mean Phase 4", `depvarmean4',"Contr. Mean Phase 5", `depvarmean5') ///
addtext("District FE", \checkmark, "Total rounds FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Respiratory Cases)
	
restore




*===========================================================================================================
                    *Supplementary Table A16 | Balance Table for ASHAs Surveyed from May 7-10 * 
*===========================================================================================================

preserve
keep if id_date > td(06may2020) && id_date < td(11may2020)
iebaltab flw_households nophone famphone ownphone whatsapp_yn yearsofschooling, grpvar(Treatment) grpcodes rowvarlabels pttest starsnoadd grplabels("0 Control @ 1 Treatment") ///
savetex("Tables/TableA16") replace
restore



*===========================================================================================================
                    *Supplementary Table A17 | Balance Table for ASHAs Sample* 
*===========================================================================================================
preserve
by unique_id (id_date), sort: keep if _n == _N
iebaltab flw_households nophone famphone ownphone whatsapp_yn yearsofschooling, grpvar(Treatment) grpcodes rowvarlabels pttest starsnoadd grplabels("0 Control @ 1 Treatment") ///
savetex("Tables/TableA17") replace
restore



*===========================================================================================================
                    *Supplementary Table A18 | Balance Table for ASHAs by Survey Cohort* 
*===========================================================================================================
preserve
by unique_id (id_date), sort: keep if _n == _N
iebaltab phase0 phase1, grpvar(Treatment) grpcodes rowvarlabels pttest starsnoadd grplabels("0 Control @ 1 Treatment") ///
savetex("Tables/TableA18") replace
restore



*==========================================================================================================
                    *Supplementary Table A19 | Balance in ASHA Survey Attrition Rates*
*==========================================================================================================

//Balance of total interview rounds over treatment assignment
preserve
duplicates drop unique_id, force 							//keep unique ASHAs 

gen never_attrit = 1 if exit_phase == .
replace never_attrit = 0 if never_attrit == .

reg total_rounds Treatment, vce(cluster pincode)
outreg2 using "Tables/TableA19", keep(Treatment) replace ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) ///
ctitle(Total Interview Rounds)

reg never_attrit Treatment, vce(cluster pincode)
outreg2 using "Tables/TableA19", keep(Treatment) append ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) ///
ctitle(Never Attrited)

restore


//Balance of interview_round on treatment assignment by phase
reghdfe interview_round TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 c.Wflw_households##phase if phase>0, absorb(id_date phase#district phase#smartphone_yn) cluster(pincode)

outreg2 using "Tables/TableA19", append keep(Treat*) ///
 label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) ///
addtext("District FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark) ///
ctitle(Interview Round)


//Balance of exit_flag over treatment assignment 
reghdfe exit_flag TreatXphase1 TreatXphase2 TreatXphase3 TreatXphase4 TreatXphase5 c.Wflw_households##phase if phase>0, absorb(id_date phase#district phase#smartphone_yn) cluster(pincode)
outreg2 using "Tables/TableA19", append keep(Treat*) ///
label tex(frag) stats(coef se pval) noaster nonotes nor2 nocons par(se) bracket(pval) dec(3) ///
addtext("District FE", \checkmark, "Smartphone FE", \checkmark, "Date FE", \checkmark ) ///
ctitle(Exit Phase) sortvar(Treatment)




*===================================================================================
         *Supplementary Table A20 | Balance Table for ASHAs Who Never Attrit*
*===================================================================================

preserve

keep if missing(exit_phase)  //only keep ASHAs who never attrited from the study
duplicates drop unique_id, force
iebaltab flw_households nophone famphone ownphone whatsapp_yn yearsofschooling, grpvar(Treatment) grpcodes rowvarlabels pttest starsnoadd savetex("Tables/TableA20") grplabels("0 Control @ 1 Treatment") replace

restore




******************************
*** END **********************
******************************




